package com.bdmc.web.controller.report;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.page.TableDataInfo;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.bo.ReportPersonStopBo;
import com.bdmc.report.domain.vo.ReportPersonStopVo;
import com.bdmc.report.service.IReportPersonStopService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;


/**
 * 工作时间内停留控制器
 *
 * @author bdmc
 * @date 2022-08-11
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/personStop")
public class ReportPersonStopController extends BaseController {

    private final IReportPersonStopService iReportpersonStopService;

    /**
     * 查询工作时间内停留列表
     */
    @SaCheckPermission("report:personStop:list")
    @GetMapping("/list")
    public TableDataInfo<ReportPersonStopVo> list(@Validated(QueryGroup.class) ReportPersonStopBo bo, PageQuery pageQuery) {
        return iReportpersonStopService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出工作时间内停留列表
     */
    @SaCheckPermission("report:personStop:export")
    @Log(title = "工作时间内停留", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportPersonStopBo bo, HttpServletResponse response) {
        List<ReportPersonStopVo> list = iReportpersonStopService.queryList(bo);
        ExcelUtil.exportExcel(list, "工作时间内停留", ReportPersonStopVo.class, response);
    }

    /**
     * 获取工作时间内停留详细信息
     */
    @SaCheckPermission("report:personStop:query")
    @GetMapping("/{personStopId}")
    public AjaxResult<ReportPersonStopVo> getInfo(@PathVariable("personStopId") Long PersonStopId) {
        return AjaxResult.success(iReportpersonStopService.queryById(PersonStopId));
    }

    /**
     * 新增工作时间内停留
     */
    @SaCheckPermission("report:personStop:add")
    @Log(title = "工作时间内停留", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportPersonStopBo bo) {
        return toAjax(iReportpersonStopService.insertByBo(bo));
    }

    /**
     * 修改工作时间内停留
     */
    @SaCheckPermission("report:personStop:edit")
    @Log(title = "工作时间内停留", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportPersonStopBo bo) {
        return toAjax(iReportpersonStopService.updateByBo(bo));
    }

    /**
     * 删除工作时间内停留
     */
    @SaCheckPermission("report:personStop:remove")
    @Log(title = "工作时间内停留" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{personStopIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] personStopIds) {
        return toAjax(iReportpersonStopService.deleteWithValidByIds(Arrays.asList(personStopIds), true));
    }
}
